import threading

from settings import KUAISHOU_COOKIE, BILIBILI_DATA_ID, BILIBILI_CF_ID
from download import Download
from log import MyLogging

log = MyLogging()


class Engine(object):
    def __init__(self):
        self.B = BliBli(BILIBILI_DATA_ID, BILIBILI_CF_ID)
        self.K = KuaiShou(KUAISHOU_COOKIE)

    def run(self):
        sem = threading.Semaphore(10)  # 设置可同时执行的最大线程数
        for data in self.K.main():
            sem.acquire()  # 获得线程，可用线程数减1
            t = Download(data, sem)  # 给执行函数传递值
            t.start()  # 执行函数


if __name__ == '__main__':
    from kuai_shou import KuaiShou
    from bilibili import BliBli
    E = Engine()
    while True:
        E.run()


